<template>
  <el-dialog
    :title="dialogTittle"
    :visible.sync="dialogFormVisible"
    width="450px"
  >
    <el-form
      class="small-space"
      v-model="model"
      label-position="right"
      label-width="24%"
    >
      <el-form-item
        v-for="(obj) in list"
        :key=obj.key
        :label="$t(obj.label)"
        :required="obj.keyword"
      >
        <el-input
          :type="obj.type"
          :disabled="obj.disable"
          v-model="model[obj.label]"
          @keyup.enter.native="onConfirm"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer"
    >
        <el-button @click="dialogFormVisible = false">{{$t('auth.common.cancel')}}</el-button>
        <el-button
          type="primary"
          @click="onConfirm"
        >{{$t('auth.common.confirm')}}</el-button>
    </div>
  </el-dialog>
</template>

<script>
/* eslint-disable */
import {
  GetRoleList,
  AddRole,
  GetRoleById,
  UpdateRole,
  DeleteRole,
  GetUserById,
  UpdateUser
} from "../../../api/role";
export default {
  data () {
    return {
      dialogFormVisible: false,
      model: {},
      list: []
    };
  },
  name: "edit",
  props: {
    dialogTittle: {
      type: String,
      default: ''
    }
  },
  methods: {
    show (bShow = true) {
      this.dialogFormVisible = bShow
    },
    getDataModel () {
      let model = {}
      for (let obj of this.list) {
        model[obj.label] = obj.default || ''
      }

      return model
    },
    onConfirm () {
      let map = new Map()
      for (let obj of this.list) {
        map.set(obj.key, this.model[obj.label])
      }

      this.$emit('onConfirm', map);
    },
    updateRole () {

    },
    /**
     * @brief 参数列表
     * list = [paramObj]
     * paramObj = {
     * key     参数唯一标识
     * label   显示名称(传入国际化key)
     * default 默认显示
     * keyword 是否是必填项
     * type    text/number/password
     * disable 是否禁用
     * }
     */
    InitDialog (list) {
      this.list = list
      this.model = this.getDataModel()
    }
  }
};
</script>


<style lang="scss" rel="stylesheet/scss" scoped>
</style>
